<!-- quirks -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
	<meta name="renderer" content="webkit"/>
	<title>Map</title>
	<link href="../ting-quirks.css" rel="stylesheet"/>
	<!--[if lt IE 9]><script src="../dist/sky-compat.js"></script><![endif]-->
	<!--[if gte IE 9]><!--><script src="../dist/sky-modern.js"></script><!--><![endif]-->
	<script src="../demo.js"></script>
</head>
<body>
<div class="container-fluid">
	<h3>Map</h3>
	<p>对象保存键值对。任何值(对象或者原始值) 都可以作为一个键或一个值。</p>
	<table class="table table-bordered table-condensed table-striped">
		<thead>
		<tr class="primary">
			<th>方法</th><th>返回</th><th>描述</th>
		</tr>
		</thead>
		<tbody class="table-hover">
		<tr>
			<td>set</td><td></td><td>添加元素</td>
		</tr>
		<tr>
			<td>has</td><td>返回布尔值</td><td>判断是否存在某个元素</td>
		</tr>
		<tr>
			<td>clear</td><td></td><td>清除内部所有元素</td>
		</tr>
		<tr>
			<td>forEach</td><td></td><td>对数组的每个元素执行一次提供的函数(回调函数)</td>
		</tr>
		<tr>
			<td>get</td><td>返回之前设置的值</td><td>获取键对应的值，如果不存在，则返回undefined</td>
		</tr>
		<tr>
			<td>delete</td><td>返回是否存在</td><td>移除 Map 对象中指定的元素</td>
		</tr>
		</tbody>
	</table>
	<pre class="code">//基本用法
var m = new Map();
m.set(1, "black");
m.set(2, "red");
m.set("toString", 2);
m.set({x:1}, 3);

m.forEach(function(value, key, mapObj){
	alert(JSON.stringify(key)+" --> "+JSON.stringify(value));
});</pre>
	<div class="btn-toolbar">
		<a class="btn btn-primary" href="javascript:void 0;" onclick="run(this)">运行</a>
	</div>
	<pre class="code">//删除
var m = new Map([[1,"22"],[2,"33"],[2,"44"],[3,"44"]]);
m['delete'](2);
alert(m.size);//2

m.clear();
alert(m.size);//0</pre>
	<div class="btn-toolbar">
		<a class="btn btn-primary" href="javascript:void 0;" onclick="run(this)">运行</a>
	</div>
	<pre class="code">//转数组
var m = new Map([[1,"22"],[2,"33"],[2,"44"],[3,"44"]]);
alert(JSON.stringify(Array.from(m)));</pre>
	<div class="btn-toolbar">
		<a class="btn btn-primary" href="javascript:void 0;" onclick="run(this)">运行</a>
	</div>
</div>
</body>
</html>